//
//  CLRequest.h
//  Charles
//
//  Created by Charles on 2018/6/6.
//  Copyright © 2018年 charles. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "CLBaseRequest.h"

FOUNDATION_EXPORT NSString *const CLRequestCacheErrorDomain;
NS_ENUM(NSInteger) {
    CLRequestCacheErrorExpired = -1,
    CLRequestCacheErrorVersionMismatch = -2,
    CLRequestCacheErrorSensitiveDataMismatch =-3,
    CLRequestCacheErrorAppVersionMismatch = -4,
    CLRequestCacheErrorInvalidCacheTime = -5,
    CLRequestCacheErrorInvalidMetadata = -6,
    CLRequestCacheErrorInvalidCacheData = -7,
};

/**
 YTKBaseRequest的子类。负责缓存的处理：请求前查询缓存；请求后写入缓存。
 */
@interface CLRequest : CLBaseRequest

@property (nonatomic) BOOL ignoreCache;

// whether data is from local cache
- (BOOL)isDataFromCache;

- (BOOL)loadCacheWithError:(NSError * __autoreleasing *)error;

- (void)startWithoutCache;

- (void)saveResponseDataToCacheFile:(NSData *)data;

- (NSInteger)cacheTimeInSeconds;

- (long long)cacheVersion;

- (id)cacheSensitiveData;

// whether cache is asynchronously written to storage. Default is YES
- (BOOL)writeCacheAsynchronously;

@end
